package com.hzsd.zengbanyi.biaodan_text.MyAdapter;



import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hzsd.zengbanyi.biaodan_text.R;
import com.hzsd.zengbanyi.biaodan_text.bean.WorkDAO;

public class DetailListAdapter extends BaseAdapter{
	private Context context;
	private ArrayList<HashMap<String, Object>> data;
	private LayoutInflater inflater;
	private WorkDAO workDAO;
	
	public DetailListAdapter(Context context,ArrayList<HashMap<String, Object>> data) {
		this.context=context;
		this.data=data;
		this.inflater=LayoutInflater.from(context);
		workDAO=new WorkDAO(context);
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHold viewHold = null;
		if(convertView==null){
			convertView=inflater.inflate(R.layout.item_detail, parent, false);
			viewHold=new ViewHold();
			viewHold.tv_sample=(TextView) convertView.findViewById(R.id.tv_sample);
			viewHold.iv_water=(ImageView) convertView.findViewById(R.id.iv_water);
			viewHold.tv_sampleCode=(TextView) convertView.findViewById(R.id.tv_sampleCode);
			convertView.setTag(viewHold);
		}else{
			viewHold=(ViewHold) convertView.getTag();
		}
		viewHold.tv_sample.setText((CharSequence) data.get(position).get("sampleGeneralPlace"));
		viewHold.tv_sampleCode.setText((CharSequence) data.get(position).get("sampleCode"));
		String sampleId=(String) data.get(position).get("sampleId");
		if(!workDAO.getSimpleIsSave(sampleId)){
			//没保存
			viewHold.iv_water.setVisibility(viewHold.iv_water.INVISIBLE);
		}else{
			//保存了
			viewHold.iv_water.setVisibility(viewHold.iv_water.VISIBLE);
		}
		return convertView;
	}

}
class ViewHold{
	TextView tv_sample;
	TextView tv_sampleCode;
	ImageView iv_water;
}
